define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        Md5 = require("../../plugins/md5/md5"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>确定是否提交？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });


    var _vm = Init.initVue({
        data : {
            check : {},
            res: {
                old_pwd : "",
                new_pwd : "",
                confirm_pwd : ""
            }
        },
        methods: {
            submit : function() {
                var obj;

                this.check.$valid();

                if (!this.check.flag) { return; }

                if (_vm.res.new_pwd === _vm.res.old_pwd) {
                    METHOD.alert("设置的新密码与旧密码一致，请重新设置");
                    return;
                } else if (_vm.res.new_pwd != _vm.res.confirm_pwd) {
                    METHOD.alert("确认的密码与设置的新密码不一致，请重新确认");
                    return;
                }

                obj = {
                    old_pwd : Md5(_vm.res.old_pwd),
                    new_pwd : Md5(_vm.res.new_pwd),
                    confirm_pwd : Md5(_vm.res.confirm_pwd)
                };

                _Dialog.showUI(function(i) {
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax("admin/modify_pwd",obj,{type : 'post'}).done(function(){
                            METHOD.loading.hide();
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }
                    this.hideUI();
                });
            }
        }
    });

});

